package com.yunzheng.studyLeaveSystem.modules.admin.show.condition.dao.lmpl;

import com.yunzheng.studyLeaveSystem.modules.admin.show.condition.entity.leaver;
import com.yunzheng.studyLeaveSystem.modules.admin.show.condition.dao.LeaveDao;
import com.yunzheng.studyLeaveSystem.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class LeaveDaoImpl implements LeaveDao {
    @Override
    public List<leaver> queryDay() throws Exception {
        Connection connection = DBUtils.getCon();
        List<leaver> usersList = new ArrayList<>();

        String sql = "select name,term, direction,leave_class, reason from leaver where leave_date = curdate();";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);



        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            leaver leaver = new leaver();
            leaver.setName(resultSet.getString("name"));
            leaver.setTerm(resultSet.getString("term"));
            leaver.setDirection(resultSet.getString("direction"));
            leaver.setLeave_class(resultSet.getString("leave_class"));
            leaver.setReason(resultSet.getString("reason"));
            usersList.add(leaver);
        }
        DBUtils.release(resultSet, preparedStatement, connection);
        return usersList;
    }

}

